/* IE Clear type fix */

(function ($) {

    $.fn.customFadeIn = function (speed, callback) {

        $(this).fadeIn(speed, function () {

            if (jQuery.browser.msie) $(this).get(0).style.removeAttribute('filter');

            if (callback != undefined) callback();

        });

    };

    $.fn.customFadeOut = function (speed, callback) {

        $(this).fadeOut(speed, function () {

            if (jQuery.browser.msie) $(this).get(0).style.removeAttribute('filter');

            if (callback != undefined) callback();

        });

    };

    $.fn.customFadeTo = function (speed, callback) {

        $(this).fadeTo(speed, function () {

            if (jQuery.browser.msie) $(this).get(0).style.removeAttribute('filter');

            if (callback != undefined) callback();

        });

    };

    $.fn.customToggle = function (speed, callback) {

        $(this).toggle(speed, function () {

            if (jQuery.browser.msie) $(this).get(0).style.removeAttribute('filter');

            if (callback != undefined) callback();

        });

    };



})(jQuery);



/* Disable autocomplete */

var flag = 1;

   function disAutoComplete(obj){

        if(flag){

      	obj.setAttribute("autocomplete","off");

            flag = 0;

      }

       //window.location = "#";

        obj.focus();

   }



/* Live Search */

function lookup(inputString){

    if(inputString.length==0){

        $('#suggestions').hide();

    }else if(inputString.length > 4) {

        $.post(SITEURL + "/ajax/liveSearch.php",{

            word: "" + inputString + ""

        },

        function(data){

            if (data.length>0) {

                $('#suggestions').fadeIn();

                $('#autoSuggestionsList').html(data);

            }

        });

    }

}

/* Voting System */

function updateVoteUp(id){

    var the_id=$('#vote_up-'+id).attr('value');

    $("span#votes_count"+id).fadeOut("fast");

    var pars='action=vote_up'+'&id='+id;

    $.ajax({

        type:"POST",

        url:SITEURL+"/ajax/voting.php",

        data:pars,

        success:function(msg){

            $("span#votes_count"+id).html(msg).fadeIn();

            $("span#vote_buttons"+id).remove();

        }

    });

}

function updateVoteDown(id){

    var the_id=$('#vote_down-'+id).attr('value');

    var pars='action=vote_down'+'&id='+id;

    $.ajax({

        type:"POST",

        url:SITEURL+"/ajax/voting.php",

        data:pars,

        success:function(msg){

            $("span#votes_count"+id).fadeOut().html(msg).fadeIn();

            $("span#vote_buttons"+id).remove();

        }

    });

}

function fill(thisValue){

    $('#keywords').val(thisValue);

    setTimeout("$('#suggestions').hide();",200);

}

function alphabetsOnly(myfield, e)
{
	var key;
	var keychar;
	
	if (window.event)
	   key = window.event.keyCode;
	else if (e)
	   key = e.which;
	else
	   return true;
	keychar = String.fromCharCode(key);
	
	e = e || window.event; 
	if (e.ctrlKey && (("vV").indexOf(keychar) > -1))
	{
		return true;
	}
	
	if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) )
	{   
		return true; 
	}

	re = /^[A-Za-z ]+$/;
	if(re.test(keychar))
	{
		return true;
	}
	return false;
}



/* Password Strenght */

(function(A){A.extend(A.fn,{pstrength:function(B){var B=A.extend({verdects:["Very weak","Weak","Medium","Strong","Very strong"],colors:["#f00","#c06","#f60","#3c0","#390"],scores:[10,15,30,40],common:["password","sex","god","123456","123","boss","letmein","qwerty","monkey"],minchar:6},B);return this.each(function(){var C=A(this).attr("id");A(this).after("<div class=\"pstrength-minchar\" id=\""+C+"_minchar\">Minimum number of characters is "+B.minchar+"</div>");A(this).after("<div class=\"pstrength-info\" id=\""+C+"_text\"></div>");A(this).after("<div class=\"indicator\"><div class=\"pstrength-bar reverse\" id=\""+C+"_bar\" style=\"width: 0%;\"></div></div>");A(this).keyup(function(){A.fn.runPassword(A(this).val(),C,B)})})},runPassword:function(D,F,C){nPerc=A.fn.checkPassword(D,C);var B="#"+F+"_bar";var E="#"+F+"_text";if(nPerc==-200){strColor="#f00";strText="Unsafe password word!";A(B).css({width:"0%"})}else{if(nPerc<0&&nPerc>-199){strColor="#888";strText="Too short";A(B).css({width:"5%"})}else{if(nPerc<=C.scores[0]){strColor=C.colors[0];strText=C.verdects[0];A(B).css({width:"10%"})}else{if(nPerc>C.scores[0]&&nPerc<=C.scores[1]){strColor=C.colors[1];strText=C.verdects[1];A(B).css({width:"25%"})}else{if(nPerc>C.scores[1]&&nPerc<=C.scores[2]){strColor=C.colors[2];strText=C.verdects[2];A(B).css({width:"50%"})}else{if(nPerc>C.scores[2]&&nPerc<=C.scores[3]){strColor=C.colors[3];strText=C.verdects[3];A(B).css({width:"75%"})}else{strColor=C.colors[4];strText=C.verdects[4];A(B).css({width:"100%"})}}}}}}A(B).css({backgroundColor:strColor});A(E).html("<span style='color: "+strColor+";'>"+strText+"</span>")},checkPassword:function(C,B){var F=0;var E=B.verdects[0];if(C.length<B.minchar){F=(F-100)}else{if(C.length>=B.minchar&&C.length<=(B.minchar+2)){F=(F+6)}else{if(C.length>=(B.minchar+3)&&C.length<=(B.minchar+4)){F=(F+12)}else{if(C.length>=(B.minchar+5)){F=(F+18)}}}}if(C.match(/[a-z]/)){F=(F+1)}if(C.match(/[A-Z]/)){F=(F+5)}if(C.match(/\d+/)){F=(F+5)}if(C.match(/(.*[0-9].*[0-9].*[0-9])/)){F=(F+7)}if(C.match(/.[!,@,#,$,%,^,&,*,?,_,~]/)){F=(F+5)}if(C.match(/(.*[!,@,#,$,%,^,&,*,?,_,~].*[!,@,#,$,%,^,&,*,?,_,~])/)){F=(F+7)}if(C.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/)){F=(F+2)}if(C.match(/([a-zA-Z])/)&&C.match(/([0-9])/)){F=(F+3)}if(C.match(/([a-zA-Z0-9].*[!,@,#,$,%,^,&,*,?,_,~])|([!,@,#,$,%,^,&,*,?,_,~].*[a-zA-Z0-9])/)){F=(F+3)}for(var D=0;D<B.common.length;D++){if(C.toLowerCase()==B.common[D]){F=-200}}return F}})})(jQuery)

//Following function is used for special charac validaiton 

function ch_validName(str)
{
      var pattern = /^([a-zA-Z \-])+$/; 
      if( pattern.test(str) )
		return true;
	else
		return false;
}

function ch_isAlphabetNumeric(str)
{
      var pattern = /^([a-zA-Z0-9])+$/; 
      if( pattern.test(str) )
		return true;
	else
		return false;
}

function ch_validTournamentName(str)
{
	var pattern = /^([a-zA-Z0-9\s\/-])+$/; 
	if( pattern.test(str) )
		return true;
	else
		return false;
}

function ch_validAlphaNumericName(str)
{
	var pattern = /^([a-zA-Z0-9\s])+$/; 
	if( pattern.test(str) )
		return true;
	else
		return false;
}


function ch_validAlphaNumericNameExtended(str)
{
	var pattern = /^([a-zA-Z0-9\s-])+$/; 
	if( pattern.test(str) )
		return true;
	else
		return false;
}


function ch_isInteger(str)
{
	var pattern = /^([0-9])+$/; 
	if( pattern.test(str) )
		return true;
	else
		return false;
}


function ch_validAddress(str)
{
	var pattern = /^([a-zA-Z0-9\s\,\#\:\.\/;-])+$/; 
	if( pattern.test(str) )
		return true;
	else
		return false;
}

function ch_validPhoneNumber(str)
{
	var pattern = /^([0-9\s\(\)\+-])+$/; 
	if( pattern.test(str) )
		return true;
	else
		return false;
}


function ch_validNewsTitle(str)
{
	var pattern = /^([a-zA-Z0-9\s-])+$/; 
	if( pattern.test(str) )
		return true;
	else
		return false;
}

function ch_validUserName(str)
{
 	var pattern = /^([a-zA-Z0-9\.])+$/; 
	if( pattern.test(str) )
		return true;
	else
		return false;
}

function ch_validCNIC(str)
{
 	var pattern = /^([0-9-])+$/; 
	if( pattern.test(str) )
		return true;
	else
		return false;
}


function ch_validEmail(str)
{
 	var pattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
	if( pattern.test(str) )
		return true;
	else
		return false;
}

 
function ch_validText(str)
{
	var pattern = /^([a-zA-Z0-9\\\s-\,\/\.'"\:&;\)\(\?])+$/; 
	if( pattern.test(str) )
		return true;
	else
		return false;
} 
 
function ch_validTextExtended(str)
{
	var pattern = /^([a-zA-Z0-9\\\s-\,\/\.'"\:&;_])+$/; 
	if( pattern.test(str) )
		return true;
	else
		return false;
} 
 

global_canel_comfirm_msg = 'Are you sure you want to navigate away from this page? \n\nThe changes you made will be lost if you navigate away from this page. \n\nPress OK to continue, or Cancel to stay on the current page.';
 